--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_wakasagihime = General:new(extension, "hy_wakasagihime", "jin_k", 3, 3, General.Female)

    local swimming_scale = fk.CreateSkill {
        name = "swimming_scale",
    }
    swimming_scale:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(swimming_scale.name) and player == target and target.phase == Player.Finish
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = room:askToChoosePlayers(player, {
                targets = room:getAlivePlayers(),
                min_num = 1,
                max_num = player.hp,
                skill_name = swimming_scale.name,
                prompt = "swimming_scale_prompt:::" .. player.hp,
            })
            if #targets > 0 then
                event:setCostData(self, targets)
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local targets = event:getCostData(self)
            room:sortByAction(targets)
            for _, t in ipairs(targets) do
                room:drawCards(t, 1, swimming_scale.name)
            end
            for _, t in ipairs(targets) do
                if not t:isNude() then
                    local success, use = room:askToUseActiveSkill(t, {
                        skill_name = "swimming_scale_active",
                        prompt = "swimming_scale_active_prompt",
                    })
                    if success and use then
                        local card = Fk:cloneCard("iron_chain")
                        card:addSubcards(use.cards)
                        room:useCard({
                            card = card,
                            from = t,
                            tos = { t }
                        })
                    end
                end
            end
        end,
    })
    swimming_scale:addEffect(fk.DetermineDamageInflicted, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(swimming_scale.name) and target == player and player.chained and data.damageType ~= fk.NormalDamage
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            player.room:drawCards(player, data.damage, swimming_scale.name)
            data:preventDamage()
        end
    })

    local swimming_scale_active = fk.CreateSkill {
        name = "swimming_scale_active",
    }
    swimming_scale_active:addEffect("active", {
        card_num = 1,
        card_filter = function(self, player, to_select, selected, selected_targets)
            local card = Fk:cloneCard("iron_chain")
            card:addSubcard(to_select)
            if not player:canUseTo(card, player) then
                return false
            end
            return #selected < 1
        end,
        target_filter = Util.FalseFunc,
        prompt = function(self, player, selected_cards, selected)
            return "swimming_scale_active_prompt"
        end,
    })

    local water_save = fk.CreateSkill {
        name = "water_save",
    }
    water_save:addEffect(fk.Damage, {
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(water_save.name) and data.from and data.from.chained and player:usedSkillTimes(water_save.name, Player.HistoryTurn) < 1
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local targets = room:askToChoosePlayers(player, {
                targets = table.filter(room:getAlivePlayers(), function(t)
                    return t.chained
                end),
                min_num = 1,
                max_num = 1,
                skill_name = water_save.name,
                prompt = "water_save_prompt1"
            })
            if #targets == 1 then
                event:setCostData(self, targets[1])
                return true
            end
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local choice1 = "water_save_choice1"
            local choice2 = "water_save_choice2"
            local choice3 = "water_save_choice_both"
            local skillTarget = event:getCostData(self)
            local choices = { choice1, choice2, choice3 }
            local valid = table.clone(choices)
            if not skillTarget:isWounded() then
                table.removeOne(valid, choice2)
            end
            local result = room:askToChoice(player, {
                choices = valid,
                all_choices = choices,
                prompt = "water_save_prompt2::" .. skillTarget.id,
                skill_name = water_save.name,
            })
            if result == choice1 then
                room:drawCards(skillTarget, 2, water_save.name)
            elseif result == choice2 then
                room:recover({
                    who = skillTarget,
                    num = 1,
                    skillName = water_save.name
                })
            elseif result == choice3 then
                room:drawCards(skillTarget, 2, water_save.name)
                room:recover({
                    who = skillTarget,
                    num = 1,
                    skillName = water_save.name
                })
                skillTarget:reset()
            end
        end
    })

    extension:loadSkillSkels { swimming_scale, swimming_scale_active, water_save }
    hy_wakasagihime:addSkills { "swimming_scale", "water_save" }

    Fk:loadTranslationTable {
        ["hy_wakasagihime"] = "若鹭姬",
        ["#hy_wakasagihime"] = "长生传说",
        ["illustrator:hy_wakasagihime"] = "亜羽瀬ひの",
        ["designer:hy_wakasagihime"] = "黑曜人形",
        ["cv:hy_wakasagihime"] = "",

        ["swimming_scale"] = "泳鳞",
        [":swimming_scale"] = "结束阶段，你可以令至多X名角色摸一张牌（X为你的体力值），以此法获得牌的角色可以将一张牌当【铁索连环】对自己使用。若你已横置，防止你受到的属性伤害并摸等量的牌。",
        ["swimming_scale_prompt"] = "泳鳞：你可以令至多%arg名角色摸一张牌",

        ["swimming_scale_active"] = "泳鳞",
        ["swimming_scale_active_prompt"] = "泳鳞：你可以将一张牌当【铁索连环】对你使用",

        ["water_save"] = "水济",
        [":water_save"] = "每回合限一次，横置的角色造成伤害后，你可以令一名横置的角色执行一项：1.摸两张牌；2.回复1点体力；背水：其复原武将牌。",
        ["water_save_prompt1"] = "水济：你可以选择一名横置的角色",
        ["water_save_prompt2"] = "水济：令%dest执行一项",
        ["water_save_choice1"] = "摸两张牌",
        ["water_save_choice2"] = "回复1点体力",
        ["water_save_choice_both"] = "背水：其复原武将牌",
    }
end
